package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.entity.Dish;
import com.itheima.entity.SetmealDish;
import com.itheima.mapper.DishMapper;
import com.itheima.mapper.SetmealDishMapper;
import com.itheima.service.SetmealDishService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * 套餐 菜品 业务实现类
 */

@Service
@Transactional
@Slf4j
public class SetmealDishServiceImpl implements SetmealDishService {

    @Autowired
    private SetmealDishMapper setmealDishMapper;

    /**
     * 套餐菜品保存
     *
     * @param setmealDish
     */
    @Override
    public void insert(SetmealDish setmealDish) {
        setmealDishMapper.insert(setmealDish);
    }


    /**
     * 删除套餐菜品表关联数据
     *
     * @param setmealIds
     */
    @Override
    public void deleteBySetmealIds(List<Long> setmealIds) {
        for (Long setmealId : setmealIds) {
            LambdaQueryWrapper<SetmealDish> lqw = new LambdaQueryWrapper<>();
            lqw.eq(SetmealDish::getDishId,setmealId);
        }
    }

    /**
     * 删除菜品表关联数据
     * @param ids
     */
    @Override
    public void deleteByDishId(List<Long> ids) {
/*
        for (Long id : ids) {
            LambdaQueryWrapper<Dish> lqw = new LambdaQueryWrapper<>();
            lqw.eq(Dish::getId, id);
        }*/

        for (Long dishId : ids) {
            LambdaQueryWrapper<Dish> lqw = new LambdaQueryWrapper<>();
            lqw.eq(Dish::getId, dishId);
        }
    }

    /**
     * 根据id查询套餐
     *
     * @param id
     */
    @Override
    public List<SetmealDish> findById(Long id) {
        LambdaQueryWrapper<SetmealDish> lqw = new LambdaQueryWrapper<>();
        LambdaQueryWrapper<SetmealDish> eq = lqw.eq(SetmealDish::getSetmealId, id);
        List<SetmealDish> setmealDishList = setmealDishMapper.selectList(eq);
        return setmealDishList;

    }
}
